<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  
  
  <title>Android基础--内容提供者ContentProvider | 不忘初心</title>
  <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
  <meta name="description" content="导语  内容提供者ContentProvider介绍">
<meta property="og:type" content="article">
<meta property="og:title" content="Android基础--内容提供者ContentProvider">
<meta property="og:url" content="http://example.com/2014/10/13/%E5%9F%BA%E7%A1%80/%E5%9F%BA%E7%A1%80--%E5%86%85%E5%AE%B9%E6%8F%90%E4%BE%9B%E8%80%85ContentProvider/index.html">
<meta property="og:site_name" content="不忘初心">
<meta property="og:description" content="导语  内容提供者ContentProvider介绍">
<meta property="og:locale" content="en_US">
<meta property="article:published_time" content="2014-10-13T01:46:09.000Z">
<meta property="article:modified_time" content="2017-07-10T06:58:07.000Z">
<meta property="article:author" content="wxyass">
<meta property="article:tag" content="Android基础">
<meta name="twitter:card" content="summary">
  
    <link rel="alternate" href="/atom.xml" title="不忘初心" type="application/atom+xml">
  
  
    <link rel="shortcut icon" href="/favicon.png">
  
  
    
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/typeface-source-code-pro@0.0.71/index.min.css">

  
  
<link rel="stylesheet" href="/css/style.css">

  
    
<link rel="stylesheet" href="/fancybox/jquery.fancybox.min.css">

  
<meta name="generator" content="Hexo 5.4.0"></head>

<body>
  <div id="container">
    <div id="wrap">
      <header id="header">
  <div id="banner"></div>
  <div id="header-outer" class="outer">
    <div id="header-title" class="inner">
      <h1 id="logo-wrap">
        <a href="/" id="logo">不忘初心</a>
      </h1>
      
    </div>
    <div id="header-inner" class="inner">
      <nav id="main-nav">
        <a id="main-nav-toggle" class="nav-icon"></a>
        
          <a class="main-nav-link" href="/">Home</a>
        
          <a class="main-nav-link" href="/archives">Archives</a>
        
      </nav>
      <nav id="sub-nav">
        
          <a id="nav-rss-link" class="nav-icon" href="/atom.xml" title="RSS Feed"></a>
        
        <a id="nav-search-btn" class="nav-icon" title="Search"></a>
      </nav>
      <div id="search-form-wrap">
        <form action="//google.com/search" method="get" accept-charset="UTF-8" class="search-form"><input type="search" name="q" class="search-form-input" placeholder="Search"><button type="submit" class="search-form-submit">&#xF002;</button><input type="hidden" name="sitesearch" value="http://example.com"></form>
      </div>
    </div>
  </div>
</header>

      <div class="outer">
        <section id="main"><article id="post-基础/基础--内容提供者ContentProvider" class="h-entry article article-type-post" itemprop="blogPost" itemscope itemtype="https://schema.org/BlogPosting">
  <div class="article-meta">
    <a href="/2014/10/13/%E5%9F%BA%E7%A1%80/%E5%9F%BA%E7%A1%80--%E5%86%85%E5%AE%B9%E6%8F%90%E4%BE%9B%E8%80%85ContentProvider/" class="article-date">
  <time class="dt-published" datetime="2014-10-13T01:46:09.000Z" itemprop="datePublished">2014-10-13</time>
</a>
    
  <div class="article-category">
    <a class="article-category-link" href="/categories/Android%E5%9F%BA%E7%A1%80/">Android基础</a>
  </div>

  </div>
  <div class="article-inner">
    
    
      <header class="article-header">
        
  
    <h1 class="p-name article-title" itemprop="headline name">
      Android基础--内容提供者ContentProvider
    </h1>
  

      </header>
    
    <div class="e-content article-entry" itemprop="articleBody">
      
        <h4 id="导语"><a href="#导语" class="headerlink" title="导语"></a>导语</h4><blockquote>
<p> 内容提供者ContentProvider介绍  </p>
</blockquote>
<span id="more"></span> 

<h1 id="一、内容提供者ContentProvider"><a href="#一、内容提供者ContentProvider" class="headerlink" title="一、内容提供者ContentProvider"></a>一、内容提供者ContentProvider</h1><h3 id="1-1-概念"><a href="#1-1-概念" class="headerlink" title="1.1 概念"></a>1.1 概念</h3><ul>
<li><p>应用的数据库是不允许其他应用访问的，数据库文件 一般是私有的。 -rw-rw- — 别的应用程序是没办法访问私有的数据库。</p>
</li>
<li><p>数据库文件私有的目的： 保证应用程序数据的安全。每个应用程序都是独立的，不可以操作另外一个应用程序数据库的数据。</p>
</li>
<li><p>有一些特殊的需求，需要把自己私有的数据库暴露给别的应用程序让别的应用程序访问。</p>
</li>
<li><p>内容提供者就是做这个事情的。</p>
<ul>
<li>内容提供者的作用就是让别的应用访问到你的私有数据<br>###1.2 自定义内容提供者</li>
</ul>
</li>
<li><p>步骤1.自定义java类，继承ContentProvider类，重写增删改查方法，在方法中写增删改查数据库的代码(重写增删改查方法分为两小步，1获取操作数据库的db对象，2利用db对象去重写增删改查方法),举例增方法<br>public class PeopleProvider extends ContentProvider {</p>
<pre><code>      private MyOpenHelper oh;//数据库创建的帮助类
      private SQLiteDatabase db;//定义数据库实例对象，这两行代码实际完成一个功能，就是获取操作数据库的db对象
  
      //用于区分同一数据库下，不同表的操作
      UriMatcher um = new UriMatcher(UriMatcher.NO_MATCH);
      &#123;
          //arg0：主机名，必须与内容提供者主机名一致
          //arg1:路径，随便写，但一般与表名相同，路径中可以携带数据
          um.addURI(&quot;com.itheima.people&quot;, &quot;person&quot;, 1);//content://com.itheima.people/person
          um.addURI(&quot;com.itheima.people&quot;, &quot;handsome&quot;, 2);//content://com.itheima.people/handsome
          um.addURI(&quot;com.itheima.people&quot;, null, 3);//content://com.itheima.people
          um.addURI(&quot;com.itheima.people&quot;, &quot;person/#&quot;, 4);//content://com.itheima.people/person/2
      &#125;
      //内容提供者创建时此方法执行（写死了此内容提供者的数据库）
      @Override
      public boolean onCreate() &#123;
          //获取操作数据库的db对象
          oh = new MyOpenHelper(getContext());
          db = oh.getWritableDatabase();
          return false;
      &#125;
      
      //根据Uri的不同，操作不同的表
      //此方法是由其他应用调用的，所以插入什么数据由其他应用决定
      @Override
      public Uri insert(Uri uri, ContentValues values) &#123;
          if(um.match(uri) == 1)&#123;//判断操作数据库中的那张表
              long id = db.insert(&quot;person&quot;, null, values);
          &#125;
          else if(um.match(uri) == 2)&#123;//判断操作数据库中的那张表
              long id = db.insert(&quot;handsome&quot;, null, values);
          &#125;
          else&#123;
              throw new IllegalArgumentException(&quot;别tm瞎传uri&quot;);
          &#125;
          return uri;
      &#125;
  &#125;
</code></pre>
</li>
<li><p>步骤2.在清单文件中定义内容提供者的标签，配置包括：内容提供者provider。配置完整类路径name，主机名authorities。注意必须要有authorities属性，这是内容提供者的主机名，功能类似地址，</p>
<pre><code>  &lt;provider android:name=&quot;com.itheima.contentprovider.PersonProvider&quot;
      android:authorities=&quot;com.itheima.people&quot;
      android:exported=&quot;true&quot;
   &gt;&lt;/provider&gt;
</code></pre>
</li>
</ul>
<p>###1.3如何在其它应用使用内容提供者查询数据</p>
<ul>
<li>创建一个其他应用，访问自定义的内容提供者，实现对数据库的插入操作</li>
</ul>
<p>public void click(View v){<br>            //得到内容分解器对象（获取内容提供者的解析器）<br>            ContentResolver cr = getContentResolver();<br>            //封装要插入的数据<br>            ContentValues cv = new ContentValues();<br>            cv.put(“name”, “小方”);<br>            cv.put(“phone”, 138856);<br>            cv.put(“money”, 3000);<br>            //通过内容提供者的解析器，实现对数据库的插入操作<br>            //arg0:用来匹配内容提供者主机名的Uri<br>            //arg1:要插入的数据<br>            //(每个应用的内容提供者内部已经通过Uri对自己应用数据库进行UriMatcher操作，只需要其它应用通过解析器匹配具体内容提供者的主机名就能调用方法完成对数据库的操作)，url:内容提供者的主机名，要加前缀content://<br>            cr.insert(Uri.parse(“content://com.itheima.person”), cv);<br>        }</p>
<p>–示例–</p>
<p>public class MainActivity extends Activity {</p>
<pre><code>        @Override
        protected void onCreate(Bundle savedInstanceState) &#123;
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
        &#125;
    
        //通过内容提供者，在其应用数据库插入数据
        public void insert(View v)&#123;
            //通过内容提供者的解析器，向01数据库插入数据
            ContentResolver cr = getContentResolver() ;
            ContentValues values = new ContentValues();
            values.put(&quot;name&quot;, &quot;巫师2&quot;);
            //values.put(&quot;money&quot;, &quot;12306&quot;);//handsome表没有money字段值，写上报错
            cr.insert(Uri.parse(&quot;content://com.itheima.people/handsome&quot;), values);
            
            values.clear();
            values.put(&quot;name&quot;, &quot;小黑2&quot;);
            values.put(&quot;money&quot;, &quot;1000000&quot;);
            cr.insert(Uri.parse(&quot;content://com.itheima.people/person&quot;), values);
        &#125;
        
        //通过内容提供者，在其应用数据库删除数据
        public void delete(View v)&#123;
            //通过内容提供者的解析器，向01数据库删除数据
            ContentResolver cr = getContentResolver() ;
            
            int i = cr.delete(Uri.parse(&quot;content://com.itheima.people/person&quot;), &quot;name=?&quot;, new String[]&#123;&quot;猴子&quot;&#125;);
            System.out.println(i);
            
        &#125;
        //通过内容提供者，在其应用数据库更新数据
        public void update(View v)&#123;
            //通过内容提供者的解析器，向01数据库更新数据
            ContentResolver cr = getContentResolver() ;
            ContentValues values = new  ContentValues();
            values.put(&quot;name&quot;, &quot;混沌骑士&quot;);
            
            int i =cr.update(Uri.parse(&quot;content://com.itheima.people/person&quot;), values, &quot;name=?&quot;, new String[]&#123;&quot;恩赐&quot;&#125;);
            System.out.println(i);
        &#125;
        //通过内容提供者，在其应用数据库查询数据
        public void query(View v)&#123;
            //通过内容提供者的解析器，向01数据库查询数据
            ContentResolver cr = getContentResolver() ;
            Cursor cursor = cr.query(Uri.parse(&quot;content://com.itheima.people/person&quot;), null, null, null, null);
            
            while(cursor.moveToNext())&#123;
                String id = cursor.getString(0);//一条记录的id字段值
                String name = cursor.getString(1);//一条记录的名字字段值
                String money = cursor.getString(cursor.getColumnIndex(&quot;money&quot;));//一条记录的money字段值
                System.out.println(id+&quot;;&quot;+name+&quot;;&quot;+money);
            &#125;
        &#125;
        
        //通过内容提供者，在其应用数据库根据id查询单条记录
        public void queryid(View v)&#123;
            //通过内容提供者的解析器，向01数据库查询数据
            ContentResolver cr = getContentResolver() ;
    
            Cursor cursor = cr.query(Uri.parse(&quot;content://com.itheima.people/person&quot;), null, &quot;_id=?&quot;, new String[]&#123;&quot;3&quot;&#125;, null);
            while(cursor.moveToNext())&#123;
                String id = cursor.getString(0);//一条记录的id字段值
                String name = cursor.getString(1);//一条记录的名字字段值
                String money = cursor.getString(cursor.getColumnIndex(&quot;money&quot;));//一条记录的money字段值
                System.out.println(id+&quot;;&quot;+name+&quot;;&quot;+money);
            &#125;
        &#125;
    &#125;
</code></pre>
<p>###1.4 UriMatcher</p>
<ul>
<li>UriMatcher作用：用于判断一条uri跟指定的多条uri中的哪条匹配（用于匹配数据库中的不同数据表，对匹配到的表进行操作）<br>#####实现UriMatcher步骤</li>
<li>1.在内容提供者类中，创建UriMatcher对象，添加匹配规则</li>
</ul>
<p>//指定多条uri<br>        um.addURI(“com.itheima.person”, “person”, PERSON_CODE);<br>        um.addURI(“com.itheima.person”, “company”, COMPANY_CODE);<br>        //#号可以代表任意数字<br>        um.addURI(“com.itheima.person”, “person/#”, QUERY_ONE_PERSON_CODE);</p>
<p>–示例–</p>
<pre><code>    UriMatcher um = new UriMatcher(UriMatcher.NO_MATCH);
    &#123;
        //arg0：主机名，必须与内容提供者主机名一致
        //arg1:路径，随便写，但一般与表名相同，路径中可以携带数据
        //arg2:若匹配怎返回该值
        um.addURI(&quot;com.itheima.people&quot;, &quot;person&quot;, 1);//content://com.itheima.people/person
        um.addURI(&quot;com.itheima.people&quot;, &quot;handsome&quot;, 2);//content://com.itheima.people/handsome
        um.addURI(&quot;com.itheima.people&quot;, null, 3);//content://com.itheima.people
        um.addURI(&quot;com.itheima.people&quot;, &quot;person/#&quot;, 4);//content://com.itheima.people/person/2
    &#125;
</code></pre>
<ul>
<li>2.在内容提供者类中，根据传入的uri,通过Uri匹配器可以实现操作不同的表</li>
</ul>
<p>@Override<br>        public Uri insert(Uri uri, ContentValues values) {<br>            if(um.match(uri) == PERSON_CODE){<br>                db.insert(“person”, null, values);<br>            }<br>            else if(um.match(uri) == COMPANY_CODE){<br>                db.insert(“company”, null, values);<br>            }<br>            else{<br>                throw new IllegalArgumentException();<br>            }<br>            return uri;<br>        }</p>
<p>–示例–</p>
<pre><code>    //接UriMatcher，根据传入的uri判断将对那张表进行操作，此插入方法是由其他应用调用的，所以插入什么数据由其他应用决定，
    @Override
    public Uri insert(Uri uri, ContentValues values) &#123;
        if(um.match(uri) == 1)&#123;
            long id = db.insert(&quot;person&quot;, null, values);
        &#125;
        else if(um.match(uri) == 2)&#123;
            long id = db.insert(&quot;handsome&quot;, null, values);
        &#125;
        else&#123;
            throw new IllegalArgumentException(&quot;别tm瞎传uri&quot;);
        &#125;
        return uri;
    &#125;
</code></pre>
<ul>
<li><p>3.另外：路径中可以携带数据，如果路径中带有数字，把数字提取出来的api</p>
<p>int id = (int) ContentUris.parseId(uri);</p>
</li>
</ul>
<p>–示例–</p>
<p>  @Override<br>        public Cursor query(Uri uri, String[] projection, String selection,<br>                String[] selectionArgs, String sortOrder) {<br>            Cursor cursor = null;<br>            if(um.match(uri) == 1){<br>                cursor = db.query(“person”, projection, selection, selectionArgs, null, null, sortOrder, null);<br>            }<br>            else if(um.match(uri) == 2){<br>                cursor = db.query(“handsome”, projection, selection, selectionArgs, null, null, sortOrder, null);<br>            }<br>            else if(um.match(uri) == 4){<br>                //把路径中携带的数字取出来<br>                long id = ContentUris.parseId(uri);<br>                cursor = db.query(“person”, projection, “_id = ?”, new String[]{id + “”}, null, null, sortOrder, null);<br>            }<br>            return cursor;<br>        }</p>
<hr>
<p>###1.5读取系统短信数据库</p>
<ul>
<li><p>只需要关注sms表    </p>
<ul>
<li><p>通过阅读源码 短信的内容提供者</p>
<pre><code>  android:authorities=&quot;sms&quot;`
</code></pre>
</li>
<li><p>content://sms/ 这个就是短信内容提供者的路径 </p>
</li>
</ul>
</li>
<li><p>只需要关注4个字段</p>
<ul>
<li>body：短信内容</li>
<li>address:短信的发件人或收件人号码（跟你聊天那哥们的号码）</li>
<li>date：短信时间</li>
<li>type：1为收到，2为发送</li>
</ul>
</li>
<li><p>读取系统短信，首先查询源码获得短信数据库内容提供者的主机名和路径，然后</p>
<p> //获取内容提供者的解析器</p>
<pre><code>  ContentResolver cr = getContentResolver();
  //查询获取每个记录有指定字段值的所有记录
  Cursor c = cr.query(Uri.parse(&quot;content://sms&quot;), new String[]&#123;&quot;body&quot;, &quot;date&quot;, &quot;address&quot;, &quot;type&quot;&#125;, null, null, null);
  //遍历每条记录
  while(c.moveToNext())&#123;
      //获取每条记录的指定字段值
      String body = c.getString(0);
      String date = c.getString(1);
      String address = c.getString(2);
      String type = c.getString(3);
      System.out.println(body+&quot;;&quot; + date + &quot;;&quot; + address + &quot;;&quot; + type);
  &#125;
</code></pre>
</li>
<li><p>读取系统短信、备份短信需要权限</p>
<pre><code>  &lt;uses-permission android:name=&quot;android.permission.READ_SMS&quot;/&gt;
  &lt;uses-permission android:name=&quot;android.permission.WRITE_EXTERNAL_STORAGE&quot;/&gt;
</code></pre>
</li>
</ul>
<p>–Activity界面读取短信到控制台，短信备份到xml文件示例</p>
<pre><code>    //创建存放短信对象的集合
    List&lt;Sms&gt; smsList = new ArrayList&lt;Sms&gt;();

    //读取系统短信，封装到短信对象
    public void click1(View v)&#123;
        //通过内容提供者获取系统短信，封装到短信对象中
        ContentResolver cr = getContentResolver();
        Cursor cursor = cr.query(Uri.parse(&quot;content://sms&quot;), new String[]&#123;&quot;body&quot;, &quot;date&quot;, &quot;type&quot;, &quot;address&quot;&#125;, null, null, null);
        while(cursor.moveToNext())&#123;
            String body = cursor.getString(0);
            long date = cursor.getLong(1);
            int type = cursor.getInt(2);
            String address = cursor.getString(3);
            Sms sms = new Sms(body, type, date, address);
            smsList.add(sms);
        &#125;
    &#125;
    //短信备份到xml文件（要先执行click1）
    public void click2(View v)&#123;
        XmlSerializer xs = Xml.newSerializer();
        File file = new File(&quot;sdcard/sms.xml&quot;);
        FileOutputStream fos;
        try &#123;
            fos = new FileOutputStream(file);
            xs.setOutput(fos, &quot;utf-8&quot;);
            
            xs.startDocument(&quot;utf-8&quot;, true);
            
            xs.startTag(null, &quot;smss&quot;);
            for (Sms sms : smsList) &#123;
                xs.startTag(null, &quot;sms&quot;);
                
                xs.startTag(null, &quot;body&quot;);
                xs.text(sms.getBody());
                xs.endTag(null, &quot;body&quot;);
                
                xs.startTag(null, &quot;date&quot;);
                xs.text(sms.getDate() + &quot;&quot;);
                xs.endTag(null, &quot;date&quot;);
                
                xs.startTag(null, &quot;type&quot;);
                xs.text(sms.getType() + &quot;&quot;);
                xs.endTag(null, &quot;type&quot;);
                
                xs.startTag(null, &quot;address&quot;);
                xs.text(sms.getAddresss());
                xs.endTag(null, &quot;address&quot;);
                
                xs.endTag(null, &quot;sms&quot;);
            &#125;
            xs.endTag(null, &quot;smss&quot;);
            
            xs.endDocument();
        &#125; catch (Exception e) &#123;
            // TODO Auto-generated catch block
            e.printStackTrace();
        &#125;
    &#125;
</code></pre>
<p>####1.5.1插入系统短信</p>
<pre><code>    ContentResolver cr = getContentResolver();
    ContentValues cv = new ContentValues();
    cv.put(&quot;body&quot;, &quot;您尾号为XXXX的招行储蓄卡收到转账1,000,000人民币&quot;);
    cv.put(&quot;address&quot;, 95555);
    //1为收到短信，2为发出短信
    cv.put(&quot;type&quot;, 1);
    cv.put(&quot;date&quot;, System.currentTimeMillis());
    cr.insert(Uri.parse(&quot;content://sms&quot;), cv);
</code></pre>
<ul>
<li><p>插入查询系统短信需要注册权限</p>
<pre><code>  &lt;uses-permission android:name=&quot;android.permission.READ_SMS&quot; /&gt;
  &lt;uses-permission android:name=&quot;android.permission.WRITE_SMS&quot;/&gt;
</code></pre>
</li>
</ul>
<p>–插入系统短信示例–</p>
<pre><code>public void click(View v)&#123;
    Thread t = new Thread()&#123;
        @Override
        public void run() &#123;
            try &#123;
                //7.5秒后插入短信
                sleep(7500);
            &#125; catch (InterruptedException e) &#123;
                e.printStackTrace();
            &#125;
            //通过内容提供者把短信插入短信数据库中
            ContentResolver cr = getContentResolver();
            ContentValues values = new ContentValues();
            values.put(&quot;address&quot;, &quot;95555&quot;);
            values.put(&quot;body&quot;, &quot;您尾号为XXXX招行储蓄卡收到转账1,000,000元人民币&quot;);
            values.put(&quot;date&quot;, System.currentTimeMillis());
            values.put(&quot;type&quot;, 1);
            cr.insert(Uri.parse(&quot;content://sms&quot;), values);
        &#125;
    &#125;;
    t.start();
&#125;
</code></pre>
<hr>
<p>###1.6 联系人的内容提供者</p>
<p>####1.6.1 联系人数据库最重要三张表</p>
<ul>
<li>raw_contacts 表  <strong>保存联系人的id</strong></li>
<li>data         表  <strong>保存联系人的数据</strong></li>
<li>mimetypes    表  <strong>保存数据的类型</strong></li>
<li>raw_contacts表：<ul>
<li>contact_id：联系人id</li>
</ul>
</li>
<li>data表：联系人的具体信息，一个信息占一行<ul>
<li>data1：信息的具体内容</li>
<li>raw_contact_id：联系人id，描述信息属于哪个联系人</li>
<li>mimetype_id：描述信息是属于什么类型</li>
</ul>
</li>
<li>mimetypes表：通过mimetype_id到该表查看具体类型</li>
</ul>
<p>####1.6.2 如何查询联系人的数据库</p>
<ol>
<li>查询raw_contacts 把 联系人的 id获取出来</li>
<li>根据id 查询data表 把这个联系人的数据取出来</li>
<li>根据mimetypes表定义的数据类型 知道这个数据是电话 邮箱 姓名。</li>
</ol>
<p>####1.6.3 联系人删除的时候重要结论<br>删除联系人并不是把联系人的数据全部清空，<br>只是把联系人的contact_id给设置为null。<br>联系人真正的数据并没有被清除还是保留在数据库里的。</p>
<p>设计的目的： 为了方便云同步。</p>
<p>####1.6.3 读取联系人</p>
<ul>
<li><p>先查询raw_contacts表拿到联系人id</p>
<pre><code>  Cursor cursor = cr.query(Uri.parse(&quot;content://com.android.contacts/raw_contacts&quot;), new String[]&#123;&quot;contact_id&quot;&#125;, null, null, null);
</code></pre>
</li>
<li><p>然后拿着联系人id去data表查询属于该联系人的信息</p>
<pre><code>  Cursor c = cr.query(Uri.parse(&quot;content://com.android.contacts/data&quot;), new String[]&#123;&quot;data1&quot;, &quot;mimetype&quot;&#125;, &quot;raw_contact_id = ?&quot;, new String[]&#123;contact_id&#125;, null);
</code></pre>
</li>
<li><p>得到data1字段的值，就是联系人的信息，通过mimetype判断是什么类型的信息</p>
<pre><code>  while(c.moveToNext())&#123;
      String data1 = c.getString(0);
      String mimetype = c.getString(1);
      if(&quot;vnd.android.cursor.item/email_v2&quot;.equals(mimetype))&#123;
          contact.setEmail(data1);
      &#125;
      else if(&quot;vnd.android.cursor.item/name&quot;.equals(mimetype))&#123;
          contact.setName(data1);
      &#125;
      else if(&quot;vnd.android.cursor.item/phone_v2&quot;.equals(mimetype))&#123;
          contact.setPhone(data1);
      &#125;
  &#125;
</code></pre>
</li>
<li><p>添加权限</p>
<pre><code>   &lt;uses-permission android:name=&quot;android.permission.READ_CONTACTS&quot;/&gt;
</code></pre>
</li>
</ul>
<p>–读取联系人示例</p>
<pre><code>    public class MainActivity extends Activity &#123;

        @Override
        protected void onCreate(Bundle savedInstanceState) &#123;
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
        &#125;
    
        public void click(View v)&#123;
            //获取内容提供者的解析器
            ContentResolver cr = getContentResolver();
            //查询raw_contacts表，获取contact_id字段的记录(所有记录)
            Cursor cursor = cr.query(Uri.parse(&quot;content://com.android.contacts/raw_contacts&quot;), new String[]&#123;&quot;contact_id&quot;&#125;, null, null, null);
            //遍历每条记录
            while(cursor.moveToNext())&#123;
                //得到每条记录中字段为contact_id的值(另外：在查询数据库表时，查询了多个字段，那么角标依次向后排，可获取一条记录中其他字段值)
                String contact_id = cursor.getString(0);
                //根据获取到的contact_id作为查询data表的条件，获取指定字段值的所有记录
                Cursor cursorData = cr.query(Uri.parse(&quot;content://com.android.contacts/data&quot;), new String[]&#123;&quot;data1&quot;, &quot;mimetype&quot;&#125;, 
                        &quot;raw_contact_id = ?&quot;, new String[]&#123;contact_id&#125;, null);
            
                //创建联系人对象，有name，phone，email 3个成员变量
                Contact contact = new Contact();
                
                //遍历从data表获取的所有符合条件的记录，从cursor中取出该联系人的信息
                while(cursorData.moveToNext())&#123;
                    //获取同一raw_contact_id下的每条记录字段data1和mimetype的值
                    String data1 = cursorData.getString(0);
                    String mimetype = cursorData.getString(1);
                    
                    //根据mimetype值不同，将同在一条记录中的data1的字段值封装到联系人对象中。
                    if(&quot;vnd.android.cursor.item/name&quot;.equals(mimetype))&#123;
                        contact.setName(data1);
                    &#125;
                    else if(&quot;vnd.android.cursor.item/phone_v2&quot;.equals(mimetype))&#123;
                        contact.setPhone(data1);
                    &#125;
                    else if(&quot;vnd.android.cursor.item/email_v2&quot;.equals(mimetype))&#123;
                        contact.setEmail(data1);
                    &#125;
                &#125;
                System.out.println(contact.toString());
            &#125;
        &#125;
    &#125;
</code></pre>
<p>####1.6.4 插入联系人</p>
<ul>
<li><p>先查询raw_contacts表，确定新的联系人的id应该是多少</p>
</li>
<li><p>把确定的联系人id插入raw_contacts表</p>
<pre><code>  cv.put(&quot;contact_id&quot;, _id);
  cr.insert(Uri.parse(&quot;content://com.android.contacts/raw_contacts&quot;), cv);
</code></pre>
</li>
<li><p>在data表插入数据</p>
<ul>
<li>插3个字段：data1、mimetype、raw_contact_id，对于同一个联系人raw_contact_id是不变的，data1和mimetype是对应改变的，多条记录才能完成对一个联系人的插入<pre><code>  cv = new ContentValues();
  cv.put(&quot;data1&quot;, &quot;赵六&quot;);
  cv.put(&quot;mimetype&quot;, &quot;vnd.android.cursor.item/name&quot;);
  cv.put(&quot;raw_contact_id&quot;, _id);
  cr.insert(Uri.parse(&quot;content://com.android.contacts/data&quot;), cv);
  
  cv = new ContentValues();
  cv.put(&quot;data1&quot;, &quot;1596874&quot;);
  cv.put(&quot;mimetype&quot;, &quot;vnd.android.cursor.item/phone_v2&quot;);
  cv.put(&quot;raw_contact_id&quot;, _id);
  cr.insert(Uri.parse(&quot;content://com.android.contacts/data&quot;), cv);
</code></pre>
</li>
</ul>
</li>
<li><p>添加权限</p>
<pre><code>  &lt;uses-permission android:name=&quot;android.permission.WRITE_CONTACTS&quot;/&gt;
  &lt;uses-permission android:name=&quot;android.permission.READ_CONTACTS&quot;/&gt;
</code></pre>
</li>
</ul>
<p>–插入联系人示例—-</p>
<pre><code>public void click(View v)&#123;
    //获取内容提供者的解析器
    ContentResolver cr = getContentResolver();
    //先查询出raw_contacts表中最新一条数据的主键,然后主键+1,就是新的联系人id
    Cursor cursor = cr.query(Uri.parse(&quot;content://com.android.contacts/raw_contacts&quot;), new String[]&#123;&quot;_id&quot;&#125;, null, null, null);
    //设置主键初始为1
    int contact_id = 1;
    //指针移动至最后一行，若成功返回true
    if(cursor.moveToLast())&#123;
        //获取每条记录中的_id
        int _id = cursor.getInt(0);
        //给conttcact_id重新赋值
        contact_id = ++_id;
    &#125;
    
    //往raw_contacts表中插入联系人id
    ContentValues values = new ContentValues();
    values.put(&quot;contact_id&quot;, contact_id);
    cr.insert(Uri.parse(&quot;content://com.android.contacts/raw_contacts&quot;), values);
    
    //往data表中插入联系人信息
    values.clear();
    values.put(&quot;data1&quot;, &quot;包九日的儿子&quot;);
    values.put(&quot;mimetype&quot;, &quot;vnd.android.cursor.item/name&quot;);
    values.put(&quot;raw_contact_id&quot;, contact_id);
    cr.insert(Uri.parse(&quot;content://com.android.contacts/data&quot;), values);
    
    values.clear();
    values.put(&quot;data1&quot;, &quot;13888888&quot;);
    values.put(&quot;mimetype&quot;, &quot;vnd.android.cursor.item/phone_v2&quot;);
    values.put(&quot;raw_contact_id&quot;, contact_id);
    cr.insert(Uri.parse(&quot;content://com.android.contacts/data&quot;), values);
&#125;
</code></pre>
<hr>
<p>#二、内容观察者ContentObserver<br>###(应用:比如数据库发生变化,发出通知,被注册的内容观察者接收并进行处理)<br>####2.1 概念</p>
<ul>
<li><p>用来接收内容提供者发出的通知<br>####2.2 内容观察者具体实现</p>
</li>
<li><p>当数据库数据改变时，内容提供者会发出通知，在内容提供者的uri上注册一个内容观察者，就可以收到数据改变的通知</p>
</li>
<li><p>1.定义观察者类</p>
</li>
<li><p>2.注册内容观察者（使用内容提供者解析器注册内容观察者）</p>
<pre><code>  //Activity一运行就执行此方法
  protected void onCreate(Bundle savedInstanceState) &#123;
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
      
      //2.注册内容观察者
      ContentResolver cr = getContentResolver();
      //arg0:指定接收哪个内容提供者发出的通知(在内容提供者的uri上注册一个内容观察者)
      //arg1:根据boolean值判断匹配精度，一般写true
      //true:表示只要是以content://sms开头的uri上的数据改变,就能收到通知
      //false：表示必须精确匹配content://sms这个uri才能收到通知，例如content://sms/inbox就收不到了
      //arg2: 传入一个观察者对象   
      cr.registerContentObserver(Uri.parse(&quot;content://sms&quot;), true, new MyObserver(new Handler()));
  &#125;

  //1.定义观察者类
  class MyObserver extends ContentObserver&#123;

      public MyObserver(Handler handler) &#123;
          super(handler);
      &#125;
      
      //收到通知时此方法调用
      @Override
      public void onChange(boolean selfChange) &#123;
          super.onChange(selfChange);
          System.out.println(&quot;短信数据库改变了&quot;);
      &#125;
  &#125;
</code></pre>
<p>####2.3在内容提供者中发通知的代码</p>
<pre><code>  ContentResolver cr = getContext().getContentResolver();
  //发出通知，所有注册在这个uri上的内容观察者都可以收到通知
  //当数据库数据改变时,发送通知
  //arg0:所有注册在这个uri上的内容观察者都能收到此通知
  cr.notifyChange(uri, null);
</code></pre>
</li>
</ul>
<p>–在内容提供者中发通知的代码示例–</p>
<pre><code>//重写内容提供者的增删改方法，并发出通知
//此方法是由其他应用调用的，所以插入什么数据由其他应用决定
@Override
public Uri insert(Uri uri, ContentValues values) &#123;
    if(um.match(uri) == 1)&#123;
        long id = db.insert(&quot;person&quot;, null, values);
        
        //当数据库数据改变时,发送通知
        //arg0:所有注册在这个uri上的内容观察者都能收到此通知
        getContext().getContentResolver().notifyChange(uri, null);
    &#125;
    else if(um.match(uri) == 2)&#123;
        long id = db.insert(&quot;handsome&quot;, null, values);
        
        //当数据库数据改变时,发送通知
        //arg0:所有注册在这个uri上的内容观察者都能收到此通知
        getContext().getContentResolver().notifyChange(uri, null);
    &#125;
    else&#123;
        throw new IllegalArgumentException(&quot;别tm瞎传uri&quot;);
    &#125;
    return uri;
&#125;
</code></pre>

      
    </div>
    <footer class="article-footer">
      <a data-url="http://example.com/2014/10/13/%E5%9F%BA%E7%A1%80/%E5%9F%BA%E7%A1%80--%E5%86%85%E5%AE%B9%E6%8F%90%E4%BE%9B%E8%80%85ContentProvider/" data-id="ckvc340qr00615dfybk5nfa9y" data-title="Android基础--内容提供者ContentProvider" class="article-share-link">Share</a>
      
      
      
  <ul class="article-tag-list" itemprop="keywords"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/Android%E5%9F%BA%E7%A1%80/" rel="tag">Android基础</a></li></ul>

    </footer>
  </div>
  
    
<nav id="article-nav">
  
    <a href="/2014/10/13/%E5%9F%BA%E7%A1%80/%E5%9F%BA%E7%A1%80--Fragment%20%E5%8A%A8%E7%94%BB/" id="article-nav-newer" class="article-nav-link-wrap">
      <strong class="article-nav-caption">Newer</strong>
      <div class="article-nav-title">
        
          Android基础--Fragment+动画
        
      </div>
    </a>
  
  
    <a href="/2014/10/13/%E5%9F%BA%E7%A1%80/%E5%9F%BA%E7%A1%80--%E5%A4%9A%E5%AA%92%E4%BD%93%E7%BC%96%E7%A8%8B/" id="article-nav-older" class="article-nav-link-wrap">
      <strong class="article-nav-caption">Older</strong>
      <div class="article-nav-title">Android基础--多媒体编程</div>
    </a>
  
</nav>

  
</article>


</section>
        
          <aside id="sidebar">
  
    
  <div class="widget-wrap">
    <h3 class="widget-title">Categories</h3>
    <div class="widget">
      <ul class="category-list"><li class="category-list-item"><a class="category-list-link" href="/categories/Activity/">Activity</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/Android-Studio%E4%BB%8B%E7%BB%8D/">Android Studio介绍</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/Android%E5%9F%BA%E7%A1%80/">Android基础</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/Android%E6%A8%A1%E6%9D%BF/">Android模板</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/BaseRecyclerViewAdapterHelper/">BaseRecyclerViewAdapterHelper</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/Bug%E9%97%AE%E9%A2%98/">Bug问题</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/Button/">Button</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/EditText/">EditText</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/Fragment/">Fragment</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/Gradle/">Gradle</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/ListView/">ListView</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/MD%E8%AF%AD%E6%B3%95/">MD语法</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/MyEclipse/">MyEclipse</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/OSS/">OSS</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/RecyclerView/">RecyclerView</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/SQL%E5%9F%BA%E7%A1%80/">SQL基础</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/UI%E6%8E%A7%E4%BB%B6/">UI控件</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/View/">View</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/ViewPager/">ViewPager</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/View%E7%AF%87/">View篇</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/as%E6%8A%A5%E9%94%99/">as报错</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/jar%E5%8C%85/">jar包</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/targetSdkVersion/">targetSdkVersion</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/%E4%B8%83%E7%89%9B%E4%BA%91/">七牛云</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/%E4%BA%8C%E7%BB%B4%E7%A0%81/">二维码</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/%E5%88%A0%E9%99%A4%E5%9B%BE%E7%89%87%E7%BC%93%E5%AD%98/">删除图片缓存</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/%E5%8D%87%E7%BA%A7%E6%8A%A5%E9%94%99/">升级报错</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/%E5%8D%9A%E5%AE%A2%E6%90%AD%E5%BB%BA/">博客搭建</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/%E5%8E%BB%E6%8E%89v7%E5%8C%85/">去掉v7包</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/%E5%9B%BE%E7%89%87%E5%A4%84%E7%90%86/">图片处理</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/%E5%A4%9A%E5%AA%92%E4%BD%93/">多媒体</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/%E5%AE%9A%E5%88%B6%E7%B1%BB/">定制类</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/%E5%B0%8F%E7%B1%B3%E6%89%8B%E6%9C%BA/">小米手机</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/%E5%B9%BF%E6%92%AD%E6%9C%BA%E5%88%B6/">广播机制</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/%E5%BE%AE%E5%8D%9A%E5%88%86%E4%BA%AB/">微博分享</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/%E6%89%93%E5%8C%85APK%E6%8A%A5%E9%94%99/">打包APK报错</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/%E6%8C%81%E4%B9%85%E5%8C%96%E5%AD%98%E5%82%A8/">持久化存储</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/%E6%97%B6%E9%97%B4%E9%80%89%E6%8B%A9DatePicker/">时间选择DatePicker</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/%E6%9C%8D%E5%8A%A1/">服务</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/%E6%9D%83%E9%99%90/">权限</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/%E6%9E%84%E5%BB%BA%E5%9F%BA%E7%B1%BB/">构建基类</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/%E6%B5%8B%E8%AF%95/">测试</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/%E7%9B%91%E5%90%AC%E9%94%81%E5%B1%8F/">监听锁屏</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/%E7%B3%BB%E7%BB%9F%E9%A1%B5%E9%9D%A2%E8%B7%B3%E8%BD%AC/">系统页面跳转</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/%E8%89%BA%E6%9C%AF%E6%8E%A2%E7%B4%A2/">艺术探索</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/%E8%AF%BB%E5%8F%96txt/">读取txt</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/%E8%BE%93%E5%85%A5%E6%B3%95/">输入法</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/%E9%9F%B3%E4%B9%90%E6%92%AD%E6%94%BE%E5%99%A8/">音乐播放器</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/%E9%BB%91%E9%A9%AC%E5%8D%AB%E5%A3%AB/">黑马卫士</a></li></ul>
    </div>
  </div>


  
    
  <div class="widget-wrap">
    <h3 class="widget-title">Tags</h3>
    <div class="widget">
      <ul class="tag-list" itemprop="keywords"><li class="tag-list-item"><a class="tag-list-link" href="/tags/Activity/" rel="tag">Activity</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/Android-Studio/" rel="tag">Android Studio</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/Android-Studio%E4%BB%8B%E7%BB%8D/" rel="tag">Android Studio介绍</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/Android%E5%9F%BA%E7%A1%80/" rel="tag">Android基础</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/Android%E6%A8%A1%E6%9D%BF/" rel="tag">Android模板</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/BaseRecyclerViewAdapterHelper/" rel="tag">BaseRecyclerViewAdapterHelper</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/Bug%E9%97%AE%E9%A2%98/" rel="tag">Bug问题</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/Button/" rel="tag">Button</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/EditText/" rel="tag">EditText</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/Fragment/" rel="tag">Fragment</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/Gradle/" rel="tag">Gradle</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/ListView/" rel="tag">ListView</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/MD%E8%AF%AD%E6%B3%95/" rel="tag">MD语法</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/MyEclipse/" rel="tag">MyEclipse</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/OSS/" rel="tag">OSS</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/RecyclerView/" rel="tag">RecyclerView</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/SQL%E5%9F%BA%E7%A1%80/" rel="tag">SQL基础</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/UI%E6%8E%A7%E4%BB%B6/" rel="tag">UI控件</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/View/" rel="tag">View</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/ViewPager/" rel="tag">ViewPager</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/View%E7%AF%87/" rel="tag">View篇</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/as%E6%8A%A5%E9%94%99/" rel="tag">as报错</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/jar%E5%8C%85/" rel="tag">jar包</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/targetSdkVersion/" rel="tag">targetSdkVersion</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/%E4%B8%83%E7%89%9B%E4%BA%91/" rel="tag">七牛云</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/%E5%8D%87%E7%BA%A7%E6%8A%A5%E9%94%99/" rel="tag">升级报错</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/%E5%8D%9A%E5%AE%A2%E6%90%AD%E5%BB%BA/" rel="tag">博客搭建</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/%E5%9B%BE%E7%89%87%E5%A4%84%E7%90%86/" rel="tag">图片处理</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/%E5%A4%9A%E5%AA%92%E4%BD%93/" rel="tag">多媒体</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/%E5%B7%A5%E4%BD%9C%E9%97%AE%E9%A2%98/" rel="tag">工作问题</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/%E5%B9%BF%E6%92%AD%E6%9C%BA%E5%88%B6/" rel="tag">广播机制</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/%E5%BA%94%E7%94%A8%E8%AF%A6%E6%83%85/" rel="tag">应用详情</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/%E5%BE%AE%E5%8D%9A%E5%88%86%E4%BA%AB/" rel="tag">微博分享</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/%E6%8C%81%E4%B9%85%E5%8C%96%E5%AD%98%E5%82%A8/" rel="tag">持久化存储</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/%E6%9C%8D%E5%8A%A1/" rel="tag">服务</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/%E6%9D%83%E9%99%90/" rel="tag">权限</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/%E6%9E%84%E5%BB%BA%E5%9F%BA%E7%B1%BB/" rel="tag">构建基类</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/%E7%94%9F%E6%B4%BB/" rel="tag">生活</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/%E7%BB%83%E6%89%8B/" rel="tag">练手</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/%E8%89%BA%E6%9C%AF%E6%8E%A2%E7%B4%A2/" rel="tag">艺术探索</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/%E8%BE%93%E5%85%A5%E6%B3%95/" rel="tag">输入法</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/%E9%AB%98%E7%BA%A7%E6%8A%80%E5%B7%A7/" rel="tag">高级技巧</a></li></ul>
    </div>
  </div>


  
    
  <div class="widget-wrap">
    <h3 class="widget-title">Tag Cloud</h3>
    <div class="widget tagcloud">
      <a href="/tags/Activity/" style="font-size: 12.5px;">Activity</a> <a href="/tags/Android-Studio/" style="font-size: 10px;">Android Studio</a> <a href="/tags/Android-Studio%E4%BB%8B%E7%BB%8D/" style="font-size: 12.5px;">Android Studio介绍</a> <a href="/tags/Android%E5%9F%BA%E7%A1%80/" style="font-size: 20px;">Android基础</a> <a href="/tags/Android%E6%A8%A1%E6%9D%BF/" style="font-size: 10px;">Android模板</a> <a href="/tags/BaseRecyclerViewAdapterHelper/" style="font-size: 10px;">BaseRecyclerViewAdapterHelper</a> <a href="/tags/Bug%E9%97%AE%E9%A2%98/" style="font-size: 10px;">Bug问题</a> <a href="/tags/Button/" style="font-size: 10px;">Button</a> <a href="/tags/EditText/" style="font-size: 10px;">EditText</a> <a href="/tags/Fragment/" style="font-size: 18.75px;">Fragment</a> <a href="/tags/Gradle/" style="font-size: 10px;">Gradle</a> <a href="/tags/ListView/" style="font-size: 17.5px;">ListView</a> <a href="/tags/MD%E8%AF%AD%E6%B3%95/" style="font-size: 11.25px;">MD语法</a> <a href="/tags/MyEclipse/" style="font-size: 13.75px;">MyEclipse</a> <a href="/tags/OSS/" style="font-size: 11.25px;">OSS</a> <a href="/tags/RecyclerView/" style="font-size: 12.5px;">RecyclerView</a> <a href="/tags/SQL%E5%9F%BA%E7%A1%80/" style="font-size: 10px;">SQL基础</a> <a href="/tags/UI%E6%8E%A7%E4%BB%B6/" style="font-size: 15px;">UI控件</a> <a href="/tags/View/" style="font-size: 10px;">View</a> <a href="/tags/ViewPager/" style="font-size: 10px;">ViewPager</a> <a href="/tags/View%E7%AF%87/" style="font-size: 10px;">View篇</a> <a href="/tags/as%E6%8A%A5%E9%94%99/" style="font-size: 10px;">as报错</a> <a href="/tags/jar%E5%8C%85/" style="font-size: 10px;">jar包</a> <a href="/tags/targetSdkVersion/" style="font-size: 10px;">targetSdkVersion</a> <a href="/tags/%E4%B8%83%E7%89%9B%E4%BA%91/" style="font-size: 10px;">七牛云</a> <a href="/tags/%E5%8D%87%E7%BA%A7%E6%8A%A5%E9%94%99/" style="font-size: 10px;">升级报错</a> <a href="/tags/%E5%8D%9A%E5%AE%A2%E6%90%AD%E5%BB%BA/" style="font-size: 12.5px;">博客搭建</a> <a href="/tags/%E5%9B%BE%E7%89%87%E5%A4%84%E7%90%86/" style="font-size: 15px;">图片处理</a> <a href="/tags/%E5%A4%9A%E5%AA%92%E4%BD%93/" style="font-size: 12.5px;">多媒体</a> <a href="/tags/%E5%B7%A5%E4%BD%9C%E9%97%AE%E9%A2%98/" style="font-size: 16.25px;">工作问题</a> <a href="/tags/%E5%B9%BF%E6%92%AD%E6%9C%BA%E5%88%B6/" style="font-size: 12.5px;">广播机制</a> <a href="/tags/%E5%BA%94%E7%94%A8%E8%AF%A6%E6%83%85/" style="font-size: 10px;">应用详情</a> <a href="/tags/%E5%BE%AE%E5%8D%9A%E5%88%86%E4%BA%AB/" style="font-size: 10px;">微博分享</a> <a href="/tags/%E6%8C%81%E4%B9%85%E5%8C%96%E5%AD%98%E5%82%A8/" style="font-size: 13.75px;">持久化存储</a> <a href="/tags/%E6%9C%8D%E5%8A%A1/" style="font-size: 12.5px;">服务</a> <a href="/tags/%E6%9D%83%E9%99%90/" style="font-size: 10px;">权限</a> <a href="/tags/%E6%9E%84%E5%BB%BA%E5%9F%BA%E7%B1%BB/" style="font-size: 10px;">构建基类</a> <a href="/tags/%E7%94%9F%E6%B4%BB/" style="font-size: 11.25px;">生活</a> <a href="/tags/%E7%BB%83%E6%89%8B/" style="font-size: 11.25px;">练手</a> <a href="/tags/%E8%89%BA%E6%9C%AF%E6%8E%A2%E7%B4%A2/" style="font-size: 10px;">艺术探索</a> <a href="/tags/%E8%BE%93%E5%85%A5%E6%B3%95/" style="font-size: 10px;">输入法</a> <a href="/tags/%E9%AB%98%E7%BA%A7%E6%8A%80%E5%B7%A7/" style="font-size: 11.25px;">高级技巧</a>
    </div>
  </div>

  
    
  <div class="widget-wrap">
    <h3 class="widget-title">Archives</h3>
    <div class="widget">
      <ul class="archive-list"><li class="archive-list-item"><a class="archive-list-link" href="/archives/2017/11/">November 2017</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2017/10/">October 2017</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2017/09/">September 2017</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2017/08/">August 2017</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2017/07/">July 2017</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2017/06/">June 2017</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2017/04/">April 2017</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2017/03/">March 2017</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2017/02/">February 2017</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2016/09/">September 2016</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2014/10/">October 2014</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2014/04/">April 2014</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2013/01/">January 2013</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2012/05/">May 2012</a></li></ul>
    </div>
  </div>


  
    
  <div class="widget-wrap">
    <h3 class="widget-title">Recent Posts</h3>
    <div class="widget">
      <ul>
        
          <li>
            <a href="/2017/11/03/Android%20Studio/Github%E4%B8%8A%E6%8F%90%E4%BA%A4%E4%BB%A3%E7%A0%81/">Github上提交代码</a>
          </li>
        
          <li>
            <a href="/2017/10/31/RecyclerView/BaseRecyclerViewAdapterHelper%E5%BA%93%E7%9A%84%E5%9F%BA%E6%9C%AC%E4%BD%BF%E7%94%A8%E6%96%B9%E6%B3%95/">BaseRecyclerViewAdapterHelper库的基本使用方法</a>
          </li>
        
          <li>
            <a href="/2017/10/31/%E5%9B%BE%E7%89%87%E5%A4%84%E7%90%86/%E4%B8%83%E7%89%9B%E4%BA%91--%E4%B8%83%E7%89%9B%E4%BA%91%E5%BF%AB%E9%80%9F%E4%B8%8A%E4%BC%A0%E5%9B%BE%E7%89%87/">七牛云快速上传图片</a>
          </li>
        
          <li>
            <a href="/2017/10/31/Gradle/Gradle--Gradle%E6%B7%BB%E5%8A%A0%E7%AC%AC%E4%B8%89%E6%96%B9%E5%BA%93%E6%8A%A5%E5%BC%82%E5%B8%B8/">Gradle添加第三方库报异常</a>
          </li>
        
          <li>
            <a href="/2017/10/26/Android%20Studio/%E8%A7%A3%E5%86%B3Android-Studio-Gradle-%E9%94%99%E8%AF%AF-%E7%BC%96%E7%A0%81GBK%E7%9A%84%E4%B8%8D%E5%8F%AF%E6%98%A0%E5%B0%84%E5%AD%97%E7%AC%A6/">解决Android Studio Gradle 错误 编码GBK的不可映射字符</a>
          </li>
        
      </ul>
    </div>
  </div>

  
</aside>
        
      </div>
      <footer id="footer">
  
  <div class="outer">
    <div id="footer-info" class="inner">
      
      &copy; 2021 wxyass<br>
      Powered by <a href="https://hexo.io/" target="_blank">Hexo</a>
    </div>
  </div>
</footer>

    </div>
    <nav id="mobile-nav">
  
    <a href="/" class="mobile-nav-link">Home</a>
  
    <a href="/archives" class="mobile-nav-link">Archives</a>
  
</nav>
    


<script src="/js/jquery-3.4.1.min.js"></script>



  
<script src="/fancybox/jquery.fancybox.min.js"></script>




<script src="/js/script.js"></script>





  </div>
</body>
</html>